package com.mall4j.cloud.coupon.controller.app;

import com.mall4j.cloud.api.coupon.bo.CouponBO;
import com.mall4j.cloud.api.coupon.dto.CouponUseReq;
import com.mall4j.cloud.api.coupon.dto.CouponUseResultDto;
import com.mall4j.cloud.common.response.ServerResponseEntity;
import com.mall4j.cloud.common.security.AuthUserContext;
import com.mall4j.cloud.coupon.dto.app.UserApplyCouponReq;
import com.mall4j.cloud.coupon.model.UserCoupon;
import com.mall4j.cloud.coupon.service.UserCouponService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * uni app 用户优惠卷接口
 * @author ljh
 */
@RestController
@RequestMapping("/a/coupon")
public class UserCouponController {

    @Autowired
    private UserCouponService userCouponService;
    @GetMapping("/list")
    ServerResponseEntity<List<UserCoupon>> userCoupon() {
        long userId = AuthUserContext.get().getUserId();
        return ServerResponseEntity.success(userCouponService.getUserCoupon(userId));
    }
    @PostMapping("/applyCoupon")
    public ServerResponseEntity<Void> applyCoupon(@RequestBody UserApplyCouponReq userApplyCouponReq) {
        long userId = AuthUserContext.get().getUserId();
        userCouponService.allocateUserCoupon(userApplyCouponReq.getCouponConfigId(),userId,"app领取");
        return ServerResponseEntity.success();
    }


}
